package com.qdu.reducer;

import com.qdu.bean.EverydayBean;
import com.qdu.bean.RentCarBean;
import com.qdu.bean.TimeBean;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;


public class MonthReducer extends Reducer<TimeBean, RentCarBean,TimeBean, RentCarBean> {

    private RentCarBean resultBean = new RentCarBean();
    @Override
    protected void reduce(TimeBean key, Iterable<RentCarBean> values, Context context) throws IOException, InterruptedException {
        int sum=0;
        int casual=0;
        int registered=0;
        int count=0;

        for (RentCarBean s :
                values) {
            sum+=s.getCount();
            casual+=s.getCasual();
            registered+=s.getRegistered();
            count++;
        }
        sum=sum/count*24;
        casual=casual/count*24;
        registered=registered/count*24;

        resultBean.set1(registered,casual,sum);
        context.write(key,resultBean);
    }
}


